//
//  TopicFirst_FirstTableViewCell.m
//  艾听歌
//
//  Created by dllo on 16/5/28.
//  Copyright © 2016年 dllo. All rights reserved.
//
#import "TopicFirst_FirstTableViewCell.h"


#define topSpace 5
#define leftSpace 10

#define frontPhotoImageW self.frontPhotoImage.frame.size.width
#define frontPhotoImageH self.frontPhotoImage.frame.size.height


@interface TopicFirst_FirstTableViewCell ()


@end

@implementation TopicFirst_FirstTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self createSubViews];
    }
    
    return self;
}

- (void)createSubViews{
    
    self.frontPhotoImage = [[UIImageView alloc]init];
    self.frontPhotoImage.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.frontPhotoImage];
    self.frontPhotoImage.userInteractionEnabled = YES;
    self.frontPhotoImage.layer.cornerRadius = 8;
    self.frontPhotoImage.clipsToBounds = YES;
    
    self.titleLabel = [[UILabel alloc]init];
//    self.titleLabel.backgroundColor = [UIColor purpleColor];
    self.titleLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.titleLabel];
    self.titleLabel.font = [UIFont systemFontOfSize:25];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.userInteractionEnabled = YES;
    
    
    self.nameLabel = [[UILabel alloc]init];
//    self.nameLabel.backgroundColor = [UIColor greenColor];
    self.nameLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.nameLabel];
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.userInteractionEnabled = YES;
    
    
    //添加轻拍手势
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    
    
    [self.frontPhotoImage addGestureRecognizer:tap1];
    [self.titleLabel addGestureRecognizer:tap2];
    [self.nameLabel addGestureRecognizer:tap3];
    

    
    
}


- (void)layoutSubviews{
    
    self.frontPhotoImage.frame = CGRectMake(leftSpace, topSpace, self.contentView.frame.size.width - leftSpace * 2, self.contentView.frame.size.height - topSpace * 2);
    
    //调整照片渐变效果
    CGFloat a = 1;
    for (double i= 0; i< self.frontPhotoImage.frame.size.height / 2; i++) {
        a = ( i / self.frontPhotoImage.frame.size.height / 2);
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, self.frontPhotoImage.frame.size.height / 2  + i, self.frontPhotoImage.frame.size.width, 1)];
        view.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha: a / 4];
        [self.frontPhotoImage addSubview:view];
    }
    self.frontPhotoImage.alpha = 0.8;

    self.titleLabel.frame = CGRectMake(leftSpace * 2, frontPhotoImageH / 5 * 3 + topSpace, frontPhotoImageW - leftSpace * 2, frontPhotoImageH / 5);
    
    self.nameLabel.frame = CGRectMake(leftSpace * 2, frontPhotoImageH / 5 * 4 + topSpace, frontPhotoImageW - leftSpace * 2, frontPhotoImageH / 5 / 2);
    
    
}


- (void)setTBCellModel:(ModuleFirst_TopicHomePageModel *)TBCellModel
{
    
    _TBCellModel = TBCellModel;
    
    [self.frontPhotoImage sd_setImageWithURL:[NSURL URLWithString:_TBCellModel.image_url] placeholderImage:[UIImage imageNamed:@"holderr"]];
    
    self.titleLabel.text = _TBCellModel.name;
    
    self.nameLabel.text = _TBCellModel.title;
    
}


//轻拍手势点击方法
- (void)tapAction{
    
    self.toTopicDetail(self.TBCellModel);
    
}



@end
